<template>
	<view class="content">
		<view class="contentbox" :style="'height:'+headHeight+'px;background-color: rgba(255, 255, 255, '+nums+')'"
			@click="goBack">
			<view class="container" :style="'height:'+navBarHeight+'px;top:'+imageTop+'px;'">
				<image :src="imageUrl +'left2.png'" mode="widthFix" class="logo"></image>
				</image>
				<view>我的发票抬头</view>
			</view>
		</view>
		<!-- {{ item.invoiceType == 2 ? "企业" : "个人" }} -->
		<image :src="imageUrl +'bg.png'" mode="widthFix" class="bg-img"></image>
		<view class="nos" :style="'margin-top: '+headHeight+'px;'"></view>
		<view class="list" v-for="(item,index) in list" :key="index" @click="editItem(item,1)">
			<view class="mo" v-if="item.defaultSign">默认</view>
			<view class="box">
				<view class="name">{{item.invoiceTitle}}</view>
				<view class="time">{{item.invoiceTaxNo}}</view>
			</view>
			<image :src="imageUrl +'left4.png'" mode="widthFix"></image>
		</view>
		<view class="null"></view>
		<view class="foot-con">
			<image :src="imageUrl +'er.png'" mode="widthFix"></image>
			<view @click="editItem({invoiceType:2},2)">添加发票抬头</view>
		</view>
	</view>
</template>

<script>
	import {
		get
	} from "../../api/myHttps";
	export default {
		data() {
			return {
				headHeight: 0,
				navBarHeight: 0,
				imageTop: 0,
				right: 0,
				nums: 0,
				list: [],
				fpType: 0
			}
		},
		onLoad(options) {
			// 获取胶囊按钮位置
			// 获取系统信息（主要是状态栏高度）
			const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
			const systemInfo = uni.getSystemInfoSync();

			// 计算顶部总高度：从屏幕顶部到导航栏底部的距离
			const statusBarHeight = systemInfo.statusBarHeight; // 状态栏高度
			const navBarHeight = menuButtonInfo.height + (menuButtonInfo.top - statusBarHeight) * 2; // 导航栏高度
			const totalTopHeight = statusBarHeight + navBarHeight; // 顶部总高度（含状态栏+导航栏）

			console.log('状态栏高度:', statusBarHeight);
			console.log('胶囊按钮信息:', menuButtonInfo);
			console.log('导航栏高度:', navBarHeight);
			console.log('顶部总高度:', totalTopHeight);
			this.headHeight = totalTopHeight
			this.navBarHeight = menuButtonInfo.height
			this.imageTop = menuButtonInfo.top
			this.right = menuButtonInfo.width + 20

			this.fpType = options.fpType;
		},
		onShow() {
			this.getList()
		},
		methods: {
			getList() {
				let ownerId = uni.getStorageSync('ownerId');
				get('/city-mobile/invoice/listMyTitle?ownerId=' + ownerId, null).then((res) => {
					console.log(res);
					this.list = res;
				})
			},
			editItem(item,type) {
				if (this.fpType == 1 && type == 1) {
					const app = getApp();
					app.globalData.updatedUserData = item;

					uni.navigateBack();
				} else {
					uni.navigateTo({
						url: '/pages/editInvoice/editInvoice?item=' + encodeURIComponent(JSON.stringify(item))
					})
				}

			},
			goBack() {
				uni.navigateBack({
					delta: 1
				})
			}
		},
		onPageScroll(e) {
			if (e.scrollTop > 10) {
				console.log(111)
				this.nums = 1
			} else {
				this.nums = 0
				console.log(222)
			}
		},
	}
</script>

<style lang="scss">
	page {
		background-color: #F4FAF7;
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.bg-img {
		width: 750rpx;
		height: 520rpx;
		position: absolute;
		top: 0;
	}

	.contentbox {
		width: 750rpx;
		position: fixed;
		top: 0;
		z-index: 999;
		transition: background-color 500ms;
		background-color: #ffffff00;

		.container {
			width: 750rpx;
			position: absolute;
			bottom: 0rpx;
			display: flex;
			align-items: center;
			height: 86rpx;

			.title-names {
				width: 750rpx;
				position: absolute;
				text-align: center;
			}

			.logo {
				margin-left: 18rpx;
				width: 40rpx;
				height: 40rpx;
				position: relative;
				z-index: 9999;
			}

			view {
				margin-left: 22rpx;
				font-size: 36rpx;
				color: #1C274C;
			}

			.seandcode {
				width: 64rpx;
				height: 64rpx;
				position: relative;
				z-index: 9999;
			}
		}
	}

	.list {
		width: 690rpx;
		margin-top: 20rpx;
		background-color: #fff;
		border-radius: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		position: relative;
		padding: 20rpx 0;

		.mo {
			position: absolute;
			top: 0;
			right: 0;
			width: 68rpx;
			height: 32rpx;
			font-size: 24rpx;
			color: #24A7CE;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 0 20rpx 20rpx 0;
			background: rgba(36, 167, 206, 0.10);
		}

		.box {
			margin-left: 20rpx;

			.name {
				font-size: 32rpx;
				color: #1C274C;
				font-weight: 600;
				line-height: 48rpx;
			}

			.time {
				font-size: 24rpx;
				line-height: 32rpx;
				margin-top: 10rpx;
				color: rgba(28, 39, 76, 0.60);
			}
		}

		image {
			width: 16rpx;
			height: 16rpx;
			margin-right: 20rpx;
		}
	}

	.foot-con {
		width: 358rpx;
		height: 88rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		position: fixed;
		bottom: calc(env(safe-area-inset-bottom) + 20rpx);
		right: 30rpx;
		border-radius: 50rpx;
		background: linear-gradient(to right, #00BBFF, #5ADA7A);
		font-weight: 600;

		image {
			width: 36rpx;
			height: 36rpx;
		}

		view {
			color: #ffffff;
			font-size: 32rpx;
			font-weight: 600;
			margin-left: 10rpx;
		}
	}

	.null {
		width: 750rpx;
		height: 128rpx;
		padding-bottom: env(safe-area-inset-bottom);
	}
</style>